function multiSelectController($scope, staffService) {
  'ngInject';

  this.view = {
    keyword: '',
    selectedItems: [],
    requesting: false,
    isNullResult: false,
  };

  this.resource = {
    searchResult: [],
  };

  this.add = (item) => {
    this.selectedItems.push(item);
  };

  this.remove = (item) => {
    const index = this.selectedItems.indexOf(item);
    this.selectedItems.splice(index, 1);
  };

  const onAjaxSearchKeywordChange = (keyword) => {
    this.view.isNullResult = false;
    if (keyword) {
      this.view.requesting = true;
      staffService
      .query({ mapParams: { fullName: keyword } })
      .then((res) => {
        this.resource.searchResult = res.rows;
        if (res.rows.length === 0) {
          this.view.isNullResult = true;
        } else {
          this.view.isNullResult = false;
        }
      })
      .finally(() => {
        this.view.requesting = false;
      });
    }
  };

  const onOptionsSearchKeywordChange = (keyword) => {

  };
  // watch search key word change
  $scope.$watch(() => this.view.keyword,
    this.msOptions ? onOptionsSearchKeywordChange : onAjaxSearchKeywordChange);
}

export default multiSelectController;
